#include "syscall.h"
#include "printk.h"

extern struct task_struct *current;

unsigned long sys_write(unsigned int fd, const char* buf, int count)
{
    int64_t ret;
    struct file* target_file = &(current->files[fd]);
    if (target_file->opened) {
        /* todo: indirect call */
        ret = current->files[fd].write(fd,buf,count);
    } else {
        printk("file not open\n");
        ret = ERROR_FILE_NOT_OPEN;
    }
    return ret;
}

int64_t sys_read(unsigned int fd, char* buf, uint64_t count) {
    int64_t ret;
    struct file* target_file = &(current->files[fd]);
    if (target_file->opened) {
        /* todo: indirect call */
        ret = current->files[fd].read(fd,buf,count);
    } else {
        printk("file not open\n");
        ret = ERROR_FILE_NOT_OPEN;
    }
    return ret;
}

unsigned long sys_getpid()
{
    //printk("!!!sys_getpid: %d\n",current->pid);
    return current->pid;
}